#pragma once

#include <string.h>
#include "CopyData.h"

VidarCopyStruct::VidarCopyStruct(short cmd, const char* data1, const char* data2)
: _cmd(cmd)
{
    if (data1)
        ToPascal(data1, _str1);

    if (data2)
        ToPascal(data2, _str2);
}

void VidarCopyStruct::ToPascal(const char* src, char dest[256])
{
    unsigned char len = strlen(src) & 0xff;
    memcpy(dest + 1, src, len);
    dest[0] = len;
}

QByteArray VidarCopyStruct::FromPascal(const char data[256])
{
    return QByteArray(data + 1, data[0]);
}

QByteArray VidarCopyStruct::Data1()
{
    return FromPascal(_str1);
}

QByteArray VidarCopyStruct::Data2()
{
    return FromPascal(_str2);
}

short VidarCopyStruct::Cmd()
{
    return _cmd;
}